﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using BCCommon;
using System.Text;
using Microsoft.AspNetCore.Mvc;
using BCService.Utils;
using BlackCoffeeRESTful.Configs;
using BCService.OA.BusinessFlowCategory;
using BCDto.OA.BusinessFlowCategory;

namespace BlackCoffeeRESTful.Controllers.Management.OA.BusinessFlowCategory
{
    /// <summary>
    /// OA系统业务流分类
    /// </summary>
    [ApiExplorerSettings(GroupName = "OAAdmin")]
    [Route("api/v1/sim/[controller]")]
    public class BusinessFlowCategoryController : ManagementBaseController
    {
        private readonly IBusinessFlowCategoryService businessFlowCategoryService;

        public BusinessFlowCategoryController(IBusinessFlowCategoryService businessFlowCategoryService)
        {
            this.businessFlowCategoryService = businessFlowCategoryService;
        }

        #region 添加OA系统业务流分类
        /// <summary>
        ///  添加OA系统业务流分类
        /// </summary>
        /// <param name="requestDto">OA系统业务流分类信息</param>
        /// <response code="201">添加OA系统业务流分类成功</response>
        /// <returns></returns>
        [HttpPost]
        [Log("添加OA系统业务流分类")]
        [ProducesResponseType(typeof(BusinessFlowCategoryDto), 201)]
        public IActionResult Post(
            [FromBody]BusinessFlowCategoryRequestDto requestDto)
        {
            var result = this.businessFlowCategoryService.Add(requestDto);
            return this.Created(string.Format("api/v1/sim/BusinessFlowCategory/{0}", result.BusinessFlowCategoryId), result);
        }
        #endregion

        #region 修改OA系统业务流分类
        /// <summary>
        ///  修改OA系统业务流分类
        /// </summary>
        /// <param name="businessFlowCategoryId">OA系统业务流分类Id</param>
        /// <param name="requestDto">OA系统业务流分类信息</param>
        /// <response code="200">修改OA系统业务流分类成功</response>
        /// <returns></returns>
        [HttpPut("{business_flow_category_id}")]
        [Log("修改OA系统业务流分类")]
        [ProducesResponseType(typeof(BusinessFlowCategoryDto), 200)]
        public IActionResult Post([FromRoute(Name = "business_flow_category_id")]long businessFlowCategoryId, [FromBody]BusinessFlowCategoryRequestDto requestDto)
        {
            BusinessFlowCategoryPutDto putDto = requestDto.As<BusinessFlowCategoryPutDto>();
            putDto.BusinessFlowCategoryId = businessFlowCategoryId;
            return this.Ok(this.businessFlowCategoryService.Update(putDto));
        }
        #endregion

        #region 删除OA系统业务流分类
        /// <summary>
        ///  删除OA系统业务流分类
        /// </summary>
        /// <param name="businessFlowCategoryId">OA系统业务流分类Id</param>
        /// <response code="204">删除OA系统业务流分类成功</response>
        /// <returns></returns>
        [HttpDelete("{business_flow_category_id}")]
        [Log("删除OA系统业务流分类")]
        public IActionResult Delete([FromRoute(Name = "business_flow_category_id")]long businessFlowCategoryId)
        {
            this.businessFlowCategoryService.Delete(businessFlowCategoryId);
            return this.NoContent();
        }
        #endregion

        #region 获取OA系统业务流分类
        /// <summary>
        ///  获取OA系统业务流分类
        /// </summary>
        /// <param name="businessFlowCategoryId">OA系统业务流分类Id</param>
        /// <response code="200">获取OA系统业务流分类</response>
        /// <returns></returns>
        [HttpGet("{business_flow_category_id}")]
        [ProducesResponseType(typeof(BusinessFlowCategoryDto), 200)]
        public IActionResult Get([FromRoute(Name = "business_flow_category_id")]long businessFlowCategoryId)
        {
            return this.Ok(this.businessFlowCategoryService.GetEntity(businessFlowCategoryId));
        }
        #endregion

        #region 获取OA系统业务流分类列表
        /// <summary>
        ///  获取OA系统业务流分类列表
        /// </summary>
        /// <response code="200">获取OA系统业务流分类列表</response>
        /// <returns></returns>
        [HttpGet]
        [ProducesResponseType(typeof(BusinessFlowCategoryDto), 200)]
        public IActionResult Get()
        {
            return this.Ok(this.businessFlowCategoryService.GetList(this.Admin.CompanyId));
        }
        #endregion

        #region 获取OA系统业务流分类（分页）
        /// <summary>
        ///  获取OA系统业务流分类（分页）
        /// </summary>
        /// <param name="businessFlowCategoryName">OA系统业务流分类名称</param>
        /// <param name="start">开始时间</param>
        /// <param name="end">结束时间</param>
        /// <param name="pageIndex">以 1 起始的页码 (默认 1)。</param>
        /// <param name="pageSize">每页要显示的行数 (默认 10)。</param>
        /// <response code="200">获取OA系统业务流分类（分页）</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<BusinessFlowCategoryDto>), 200)]
        public IActionResult Query([FromQuery(Name = "business_flow_category_name")]string businessFlowCategoryName,
            [FromQuery(Name = "start")]DateTime? start,
            [FromQuery(Name = "end")]DateTime? end,
            int pageIndex = 1,
            int pageSize = 10)
        {
            return this.Ok(this.businessFlowCategoryService.Query(this.Admin.CompanyId,businessFlowCategoryName, start, end, pageIndex, pageSize));
        }
        #endregion
    }
}

